package com.huiquan.symptom.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.symptom.domain.Symptom;
import com.huiquan.symptom.domain.SymptomReveal;
import com.huiquan.framework.base.EnhancedBaseDao;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class SymptomDao extends EnhancedBaseDao<Symptom> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "SYMPTOM.";

	public SymptomDao() {
		super(space);
	}

	public void setBlacklistFlag(String id, Integer flag, Long uid) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("blacklistFlag", flag);
		param.put("modifierId", uid);
		update(space + "SET_BLACKLIST_FLAG", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveMisNameList() {
		return (List<String>) this.list(space + "RETRIEVE_MIS_NAME_LIST", sqlMapClient);
	}

	public void initList() {
		this.insert(space + "INIT_LIST", sqlMapClient);
	}

	/**
	 * 检索得到展现词数量
	 * 
	 * @param param
	 * @return
	 */
	public int selectRevealSize(Map<String, Object> param) {
		return (int) this.object(space + "SELECT_REVEAL_SIZE", param, sqlMapClient);
	}

	/**
	 * 检索得到展现词列表
	 * 
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<SymptomReveal> selectRevealList(Map<String, Object> param) {
		return (List<SymptomReveal>) this.list(space + "SELECT_REVEAL_LIST", param, sqlMapClient);
	}

	/**
	 * 检索得到无限制的展现词列表
	 * 
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<SymptomReveal> selectRevealListNoLimit() {
		return (List<SymptomReveal>) this.list(space + "SELECT_REVEAL_LIST_NOLIMIT", sqlMapClient);
	}

	/**
	 * 根据id检索得到展现词
	 * 
	 * @param id
	 * @return
	 */
	public SymptomReveal selectRevealById(int id) {
		return (SymptomReveal) this.object(space + "SELECT_REVEAL_BY_ID", id, sqlMapClient);
	}

	/**
	 * 根据原词和选择的同义词得到同义词的相关信息
	 * 
	 * @param symptomStd
	 * @param synonym
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, String> selectSynonymWithStd(String symptomStd, String synonym) {
		Map<String, String> param = new HashMap<>();
		param.put("symptomStd", symptomStd);
		param.put("synonym", synonym);
		return (Map<String, String>) this.object(space + "SELECT_SYNONYM_WITH_STD", param, sqlMapClient);
	}

	/**
	 * 更新一条展现词
	 * 
	 * @param param
	 */
	public void updateReveal(Map<String, Object> param) {
		this.update(space + "UPDATE_REVEAL", param, sqlMapClient);
	}

	/**
	 * 插入一条展现词日志
	 * 
	 * @param param
	 */
	public void insertRevealLog(Map<String, Object> param) {
		this.insert(space + "INSERT_REVEAL_LOG", param, sqlMapClient);
	}

	/**
	 * 清除掉未校验的展现词
	 */
	public void deleteNoLabelRevealData() {
		this.delete(space + "DELETE_NOLABEL_REVEAL_DATA", sqlMapClient);
	}

	/**
	 * 检索重复的同义词数据
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<String> selectRepeatSynonym() {
		return (List<String>) this.list(space + "SELECT_REPEAT_SYNONYM", sqlMapClient);
	}

	/**
	 * 将临时表中增量的部分导入展现词同义词表
	 */
	public void insertRevealSynonymWithTemp() {
		this.insert(space + "INSERT_REVEAL_SYNONYM_WITH_TEMP", sqlMapClient);
	}

	/**
	 * 将临时表中增量的部分添加到展现词表
	 */
	public void insertRevealWithTemp() {
		this.insert(space + "INSERT_REVEAL_WITH_TEMP", sqlMapClient);
	}

	/**
	 * 将未标记展现词数据与同义词最高频一致的部分置为已校验
	 */
	public void updateRevealNoLabelStatusWithSynonym() {
		this.update(space + "UPDATE_REVEAL_NOLABEL_STATUS_WITH_SYNONYM", sqlMapClient);
	}

	/**
	 * 将未标记展现词数据中展现词包含“左”、“右”的数据，状态标记为其他(3)
	 */
	public void updateRevealNoLabelStatusToOther() {
		this.update(space + "UPDATE_REVEAL_NOLABEL_STATUS_TO_OTHER", sqlMapClient);
	}

	/**
	 * 这两种情况，未校验可以批量改为已校验: 1. 展现词包含“单侧”; 2. 频数最高的同义词包含‘左’、‘右’、‘双’，展现词不包括这类词。
	 */
	public void batchUpdateRevealStatus() {
		this.update(space + "BATCH_UPDATE_REVEAL_STATUS", sqlMapClient);
	}

	/**
	 * 删除同义词表中与临时表冲突的部分
	 */
	public void deleteRevealSynonymWithTemp() {
		this.delete(space + "DELETE_REVEAL_SYNONYM_WITH_TEMP", sqlMapClient);
	}

	public void initRevealElementStd() {
		this.update(space + "INIT_REVEAL_ELEMENT_STD", sqlMapClient);
	}

	public void updateStdArrayWithTemp() {
		this.update(space + "UPDATE_STD_ARRAY_WITH_TEMP", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveRevealStdArrayList() {
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_REVEAL_STD_ARRAY_LIST", sqlMapClient);
	}
	/**
	 * 查询二元组初始化症状数据查询
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveDyadInitSymptomList() {
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_DYAD_INIT_SYMPTOM", sqlMapClient);
	}
}
